/* Copyright.

 */
include_js("js/jquery-min.js");
include_js("script/api.js");


var baseUrl = "http://192.168.80.21:8980/js/a/";
var saveUrl="http://192.168.80.21:8980/";


function logout(){
    $api.clearStorage();
    window.location.href="login.html";
}

function toView(targetUrl){
    window.location.href=targetUrl;
}

function include_js(path)
{     
    document.write("<script  src='"+path+"'></script>");
}

// 获取URL参数
function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] === variable) {
            return decodeURI(pair[1]);
        }
    }
    return false;
}

function dateSubStr(dateStr, l, r){
    if(dateStr.length>=19){
        return dateStr.substring(l,r);
    }
    return "";
}

// 防止返回undefined
function noUndefined(info){
    if(info)
        return info;
    return "";
}

function goBack(){
    window.history.back();
}


function getDictList(dictType){
    var res;
    var __sid = $api.getStorage("sessionid");
    var url = baseUrl+"dictUtil/getDictLists?dictType="+dictType;
    $.ajax({
        url:url,
        type:"get",
        headers:{
            "__sid": __sid
        },
        async:false,
        contentType:"application/json;charset=utf-8",
        success: function (result) {
            if(result.code=="ok"){
                res = result.data;
            }else{
                alert(result);
                toView("login.html");
            }
        },
        error: function (e) {
            alert(JSON.stringify(e));
        }
    });
    return res;
}

function getDictMap(dictType){
    var __sid = $api.getStorage("sessionid");
    var url = baseUrl+"dictUtil/getDictMap?dictType="+dictType;
    $.ajax({
        url:url,
        type:"get",
        headers:{
            "__sid": __sid
        },
        contentType:"application/json;charset=utf-8",
        success: function (result) {
            if(result.code=="ok"){
                return result.data;
            }else{
                alert(result);
                toView("login.html");
            }
        },
        error: function (e) {
            alert(JSON.stringify(e));
        }
    });
}